package com.example.xbrother.rule.aircondition;

import com.alibaba.fastjson.JSON;
import com.example.xbrother.rule.BaseBean;
import com.example.xbrother.rule.MaterialResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.util.List;

/**
 * 空调类型-bean
 */
@Slf4j
public class AirConditionTypeBean extends BaseBean {
    /**
     * 添加物料
     */
    public void add(AirConditionTypeParam p) {
        String fileName = null;
        if (p.getAirConditionerType().contains("列间空调")) {
            fileName = "aircondition_column.xlsx";
        } else if (p.getAirConditionerType().contains("底座空调")) {
            fileName = "aircondition_bed.xlsx";
        }
        try {
            File excelFile = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "easy_rules/aircondition" + File.separator + fileName);
            String materialJsonStr = positionMaterialInExcel(excelFile, 1, p.getEachItPower(), p.getItBoxNum(), 1, 0);
            List<MaterialResult> excelMaterialResult = JSON.parseArray(materialJsonStr, MaterialResult.class);
            log.info("excelMaterialResult = {}", JSON.toJSONString(excelMaterialResult));
            List<MaterialResult> result = p.getResult();
            result.addAll(excelMaterialResult);
        } catch (Exception e) {
            log.error("物料处理失败，{}", e.getMessage());
        }
    }
}

